package com.etc.controller;

import com.etc.entity.HotelInfo;
import com.etc.service.HotelService;
import com.etc.util.Layui;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/HotelController")
public class HotelController {

    //调用业务层
    @Autowired
    HotelService service;

    /**
     * 查询所有酒店信息
     * @param pageNum
     * @param pageSize
     * @param hotel_name
     * @param hotel_city
     * @param hotel_address
     * @return
     */
    @RequestMapping("/getAllHotel")
    @ResponseBody
    public Layui getAllHotel(@RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
                             @RequestParam(value = "pageSize",defaultValue = "3")int pageSize,
                             @RequestParam(value = "hotel_name",defaultValue = "")String hotel_name,
                             @RequestParam(value = "hotel_city",defaultValue = "")String hotel_city,
                             @RequestParam(value = "hotel_address",defaultValue = "")String hotel_address){
        PageInfo<HotelInfo> pageInfo= service.getAllHotel(pageNum,pageSize,hotel_name,hotel_city,hotel_address);
        return Layui.data(pageInfo.getTotal(),pageInfo.getList());
    }

    //添加酒店信息
    @RequestMapping("/getAddHotel")
    @ResponseBody
    public boolean getAddHotel(@RequestParam(value = "hotel_name")String hotel_name,
                        @RequestParam(value = "hotel_city")String hotel_city,
                        @RequestParam(value = "hotel_address")String hotel_address,
                        @RequestParam(value = "hotel_tel")String hotel_tel){
        //调用业务层
        boolean fian = service.getAddHotel(hotel_name,hotel_city,hotel_address,hotel_tel);
        return fian;
    }

    //根据id删除酒店信息
    @RequestMapping("/getUpdateHotel")
    @ResponseBody
    public boolean getUpdateHotel(@RequestParam(value ="hotel_id")String hotel_id){
        //调用业务层
        boolean fian1 = service.getUpdateHotel(hotel_id);
        return fian1;
    }
    //添加酒店信息
    @RequestMapping("/getModHotel")
    @ResponseBody
    public  boolean  getModHotel(@RequestParam(value = "hotel_id")String hotel_id,
                           @RequestParam(value = "hotel_name")String hotel_name,
                           @RequestParam(value = "hotel_city")String hotel_city,
                           @RequestParam(value = "hotel_address")String hotel_address){
        //调用业务层
        boolean  fian2 = service.getModHotel(hotel_id,hotel_name,hotel_city,hotel_address);
        return  fian2;
    }
}
